//
//  CancelTaskHud.m
//  UEAssistant
//
//  Created by mac on 2017/5/10.
//  Copyright © 2017年 youyixinxi. All rights reserved.
//

#import "CancelTaskHud.h"

@interface CancelTaskHud ()

@property (nonatomic, strong) UIView                *baseView;
@property (nonatomic, strong) UIView                *whiteView;
@property (nonatomic, strong) UIImageView           *yellowView;
@property (nonatomic, strong) UILabel               *textLabel;
@property (nonatomic, strong) UIButton              *continBut;
@property (nonatomic, strong) UIButton              *cancelBut;

@end

@implementation CancelTaskHud

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    _baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width - 40*Radio, Screen_Width - 40*Radio -130*Radio)];
    _baseView.backgroundColor = [UIColor clearColor];
    [self addSubview:_baseView];
    
    _yellowView = [[UIImageView alloc]initWithFrame:CGRectMake((Screen_Width-40*Radio)/2-30*Radio, 0, 60*Radio, 60*Radio)];
    _yellowView.image = [UIImage imageNamed:@"prompt"];
    [self addSubview:_yellowView];
    
    _whiteView = [[UIView alloc]initWithFrame:CGRectMake(0, 23*Radio, Screen_Width - 40*Radio, Screen_Width - 40*Radio -130*Radio)];
    _whiteView.backgroundColor = [UIColor whiteColor];
    _whiteView.layer.cornerRadius = 5;
    _whiteView.layer.masksToBounds = YES;
    [_baseView addSubview:_whiteView];
    
    _textLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*Radio, _whiteView.frame.origin.x+60*Radio, Screen_Width-20*Radio*4, 70*Radio)];
    _textLabel.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    _textLabel.textColor = RGB(51, 51, 51, 1);
    _textLabel.numberOfLines = 0;
    _textLabel.font = [UIFont systemFontOfSize:FLEXIBLE(13)];
    NSString *text = @"确定要对此文件停止自动派稿吗？停止派稿后，可以手动派稿或再次启动自动派稿。";
    // 调整行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];
    [paragraphStyle setAlignment:NSTextAlignmentCenter];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
    _textLabel.attributedText = attributedString;
    [_baseView addSubview:_textLabel];
    
    _cancelBut = [UIButton buttonWithType:UIButtonTypeSystem];
    _cancelBut.frame = CGRectMake(30*Radio, _textLabel.frame.origin.y+_textLabel.frame.size.height+20*Radio, 130*Radio, 45*Radio);
    _cancelBut.backgroundColor = [UIColor clearColor];
    [_cancelBut setTitleColor:RGB(174, 174, 174, 1) forState:UIControlStateNormal];
    [_cancelBut setTitle:@"停止派稿" forState:UIControlStateNormal];
    _cancelBut.layer.cornerRadius = 5;
    _cancelBut.layer.borderWidth = 1.f;
    _cancelBut.layer.borderColor = RGB(192, 192, 192, 1).CGColor;
    [_cancelBut addTarget:self action:@selector(cancelTaskClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_baseView addSubview:_cancelBut];
    
    _continBut = [UIButton buttonWithType:UIButtonTypeSystem];
    _continBut.frame = CGRectMake(Screen_Width-40*Radio-130*Radio-30*Radio, _textLabel.frame.origin.y+_textLabel.frame.size.height+20*Radio, 130*Radio, 45*Radio);
    _continBut.backgroundColor = RGB(53, 172, 223, 1);
    [_continBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_continBut setTitle:@"继续派稿" forState:UIControlStateNormal];
    _continBut.layer.cornerRadius = 5;
    [_continBut addTarget:self action:@selector(continAssignClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_baseView addSubview:_continBut];

}

- (void)cancelTaskClicked:(UIButton *)sender{

    if ([self.delegate respondsToSelector:@selector(cancelHudClicked:)]) {
        [self.delegate cancelHudClicked:sender];
    }

}

- (void)continAssignClicked:(UIButton *)sender{

    if ([self.delegate respondsToSelector:@selector(cancelHudClicked:)]) {
        [self.delegate cancelHudClicked:sender];
    }

}

@end
